<template>
	<view class="baseForm">
		<!-- 当前作业 -->
		<view class="activeHeight">
			<!-- 列表 -->
			<u-list ref="tableScroll" class="list" v-if="tableList.length">
				<u-list-item v-for="(item, index) in tableList" :key="item.id">
					<view class="card">
						<view class="flex record-title">
							<text class="line1">{{ item.spareName }}</text>
							<text>
								{{
									useDictionaryStore().filterDictName(
										"SpareType",
										item.spareType
									)
								}}
							</text>
						</view>
						<view
							class="flex flex-col justify-between flex-1 h-full record-content-body">
							<view class="record-content">
								<view class="record-item">
									<text>备件编号</text>
									<text>{{ item.spareCode || "" }}</text>
								</view>
								<view class="record-item">
									<text>使用数量</text>
									<text class="">
										<text>
											{{ item.sparePartNumber || 0 }}
										</text>
										<text>{{ item.spareUnit || "" }}</text>
									</text>
								</view>
							</view>
						</view>
					</view>
				</u-list-item>
			</u-list>
			<view class="flex justify-center" v-show="tableLoading">
				<u-loading-icon color="#000a7b"></u-loading-icon>
			</view>
			<!-- 空数据 -->
			<view v-show="tableList.length === 0 && !tableLoading">
				<u-empty
					mode="list"
					icon="http://cdn.uviewui.com/uview/empty/list.png"></u-empty>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
import { http } from "@/utils/http";
import { useDictionaryStore } from "@/stores/useDictionaryStore";

const props = defineProps({
	id: {
		type: String,
		default: "",
	},
	assetKind: {
		type: String,
		default: "",
	},
});

// 待完成数据
const tableList = ref([]);
const tableLoading = ref(false);
const mock = [
	{
		sparePartNumber: "200",
		spareUnit: "个",
		spareCode: "PARTS-202526",
		spareName: "利浦热芯盒射芯机",
		spareType: "1",
	},
	{
		sparePartNumber: "20",
		spareUnit: "吨",
		spareCode: "PARTS-202526",
		spareName: "利浦热芯盒射芯机",
		spareType: "2",
	},
	{
		sparePartNumber: "200",
		spareUnit: "个",
		spareCode: "PARTS-202526",
		spareName: "利浦热利浦热芯盒射芯机芯盒利浦",
		spareType: "2",
	},
];

onShow(() => {
	loadmore();
});

onPullDownRefresh(() => {
	// searchList();
	loadmore();
});

async function loadmore() {
	try {
		tableLoading.value = true;
		const result: any = await http({
			method: "GET",
			url: `/eam/eamplanrepairorder/get/${props.id}`,
			data: {
				assetKind: props.assetKind || "3",
			},
		}).finally(() => {
			tableLoading.value = false;
			uni.stopPullDownRefresh();
		});
		tableList.value = result.data.parts || [];
		// tableList.value = mock
	} catch (e) {
		console.log(e);
	}
}
</script>

<style lang="scss" scoped>
uni-page-body {
	height: 100%;
	background-color: #fbfbff;
}
.search {
	:deep(.u-search__content) {
		box-shadow: 0 1px 8px 0px rgb(19 10 236 / 8%);
	}
}
.baseForm {
	background-color: #fbfbff;
	.tab-bar {
		padding: 0 20px;
	}
	.u-line {
		padding: 10px 0;
	}
}
.list {
	.card {
		margin: $uni-page-padding;
		margin-top: 5px;
		margin-bottom: 4px;
		border-radius: 7px;
		padding: 12px 20px 0px 20px;
		transition: all 300ms ease;
		border: 1px solid #efefef;
		background-color: #fff;
		.card-flex {
			display: flex;
			align-items: flex-start;
		}
		.right {
			flex: 1;
		}
		.title {
			font-size: 14px;
			line-height: 40px;
			height: 40px;
			margin-top: 8px;
			font-weight: bold;
			color: #101010;
			border-top: 1px solid #e5ebff;
		}
		.uni-btn {
			float: right;
			font-size: 12px;
			height: 24px;
			line-height: 24px;
			padding: 0 15px;
			margin-top: 7px;
			font-weight: 400;
		}
		.des {
			font-size: 12px;
			line-height: 20px;
			margin-bottom: 3px;
		}
		.left {
			flex-basis: calc(50% + 10px);
		}
	}
}

.record-title {
	display: flex;
	justify-content: space-between;
	margin: 2px 0 2px 0;
	color: $primary-color;
	uni-text:nth-child(1) {
		font-weight: bold;
		font-size: 15px;
	}
	uni-text:nth-child(2) {
		font-weight: bold;
		font-size: 15px;
		min-width: 60px;
		text-align: right;
	}
}
.record-item {
	margin: 7px 0 !important;
	color: #8f8e94 !important;
}
</style>
